﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AvatarHelper;
using Avatar.Model;

public partial class UserControl_CompanyAddressMap : System.Web.UI.UserControl
{
    string _company = string.Empty;
    public string Company
    {
        get 
        {
            return _company;
        }
        set
        {
            _company = value;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (string.IsNullOrEmpty(_company))
            {
                lbl_Script.Text = "错误：为指定单位名称。";
            }
            else
            {
                using (var _adc = DBHelper.GetDataContext())
                {
                    var _companyMap = _adc.CompanyMap.FirstOrDefault(m => m.User == (_adc.CompanyInformation.FirstOrDefault(c => c.User == _company || c.CompanyName == _company).User));
                    if (_companyMap != null)
                    {
                        var _x = _companyMap.X;
                        var _y = _companyMap.Y;

                        var _script = @"<script language='JavaScript'>var mapOptions = new MMapOptions();mapOptions.zoom = 15;mapOptions.center = new MLngLat(" + _x + ", " + _y + ");var mapObj = new MMap('mapObj', mapOptions);</script>";

                        lbl_Script.Text = _script;
                    }
                    else
                    {
                        lbl_Script.Text = "该公司未提供地图信息标注。";
                    }
                }
            }
        }
    }
}
